package singleton.lazy.security;

import lombok.SneakyThrows;

import java.lang.reflect.Constructor;


public class ReflectInjectionEnum {
    @SneakyThrows
    public static void main(String[] args) {

//        SingletonEnum instance1 = SingletonEnum.INSTANCE;
//        SingletonEnum instance2 = SingletonEnum.INSTANCE;
//        System.out.println(instance1 == instance2);
//        System.out.println(instance1.hashCode());
//        System.out.println(instance2.hashCode());
//
//        instance1.sayOK();

        //获取到类定义
        Class x = SingletonEnum.class;
        //获取构造器
        Constructor constructor = x.getDeclaredConstructors()[0];
        //设置可以访问
        constructor.setAccessible(true);
        SingletonEnum o = (SingletonEnum) constructor.newInstance();
        //获取单例
        SingletonEnum instance = SingletonEnum.INSTANCE;
        //比较单例与初始化的实例
        if (instance == o) {
            System.out.println("相同的实例");
        } else {
            System.out.println("不同的实例");
        }
    }
}
